import SendKeys
from watsup.launcher import *
from watsup.winGuiAuto import *
from watsup import winGuiAuto
    
def clickPopupButton(popupHwnd, buttonText):
    noButton = findControl(popupHwnd, wantedText=buttonText, wantedClass="Button")
    clickButton(noButton)
    
def setCheckBox(hwnd, value):
    win32gui.SendMessage(hwnd, win32con.BM_SETCHECK, value, 0)
        
def selectTopMost(controls):
    # When the watsup methods looking for a specific component fail to return just the one exact item,
    # one can use this method to select a compo which is located at the top.
    mostRect = win32gui.GetWindowRect(controls[0])
    mostControl = controls[0]
    for control in controls:
        tempRect = win32gui.GetWindowRect(control)
        if tempRect[1] < mostRect[1]:
            mostRect = tempRect
            mostControl = control
    return mostControl
    
def ClickButton(form, controlText):
    button = findControl(form, wantedText=controlText)
    clickButton(button)
    
def clickButtonPost(hwnd):
    win32gui.PostMessage(win32gui.GetParent(hwnd),
         win32con.WM_COMMAND,
         winGuiAuto._buildWinLong(win32con.BN_CLICKED, win32api.GetWindowLong(hwnd, win32con.GWL_ID)),
         hwnd)
